package com.jxtti.service;

import org.apache.log4j.Logger;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jxtti.dao.TAirCityHourAQIDataPublishDao;
import com.jxtti.entity.TAirCityHourAQIDataPublish;

/**
 * 
 * <br>
 * <b>功能：</b>TAirCityHourAQIDataPublishService<br>
 * <b>作者：lwb</b><br>
 * <b>日期：</b> Nov 26, 2015 <br>
 * <b>版权所有：<b>版权所有(C) 2015，<br>
 */
@Service("tAirCityHourAQIDataPublishService")
@Transactional(rollbackFor = { RuntimeException.class, Exception.class })
public class TAirCityHourAQIDataPublishService {

	private final static Logger log= Logger.getLogger(TAirCityHourAQIDataPublishService.class);
	

	

	@Autowired
    private TAirCityHourAQIDataPublishDao tAirCityHourAQIDataPublishDao;

		


	/**
	 * 获取信息数据列表
	 * 
	 * @param data
	 * @return
	 */
	public Map<String, Object> list(Map<String, Object> data,  TAirCityHourAQIDataPublish tAirCityHourAQIDataPublish)
	{
		int pageNum = Integer.parseInt((data.get("currentPage") == null || data
				.get("currentPage").equals("0")) ? "1" : data.get("currentPage").toString());
		// 每页显示条数 
		int pageSize = Integer.parseInt((data.get("pageSize") == null || data.get("pageSize").equals("0")) ? "10" : data.get("pageSize").toString());
		PageHelper.startPage(pageNum, pageSize);
		PageInfo<TAirCityHourAQIDataPublish> pages = new PageInfo<TAirCityHourAQIDataPublish>( tAirCityHourAQIDataPublishDao.queryByList(data));
		data.put("page", pages);
		return data;
	}
	
	
	
	/**
	 * 查询所有数据。 
	 * @param data
	 * @return
	 */
	public List<TAirCityHourAQIDataPublish>  queryAll(Map<String, Object> data)
	{
		return  tAirCityHourAQIDataPublishDao.queryByList(data);
	}
	
	//辅助决策
	public List<Map<String, Object>>  querylatestTAirCityHourAQI(Map<String, Object> data)
	{
		return  tAirCityHourAQIDataPublishDao.queryThelatestTAirCityHourAQI(data);
	}
	
	/**
	 * 添加数据.
	 * 
	 * @param data
	 * @return
	 */
	public int add(TAirCityHourAQIDataPublish tAirCityHourAQIDataPublish)
	{
		int insertCount = tAirCityHourAQIDataPublishDao.add(tAirCityHourAQIDataPublish);
		return insertCount;
	}
	

	/**
	 * 修改数据.
	 * 
	 * @param data
	 * @return
	 */
	public int update(TAirCityHourAQIDataPublish tAirCityHourAQIDataPublish)
	{
		int updateCount = tAirCityHourAQIDataPublishDao.update(tAirCityHourAQIDataPublish);
		return updateCount;
	}
	

	/**
	 * 删除数据.
	 * 
	 * @param data
	 * @return
	 */
	public int delete(TAirCityHourAQIDataPublish tAirCityHourAQIDataPublish)
	{
		int deleteCount = tAirCityHourAQIDataPublishDao
				.delete(tAirCityHourAQIDataPublish);
		
		return deleteCount;
	}
	
	
	public TAirCityHourAQIDataPublish queryTAirCityHourAQIDataPublishById(TAirCityHourAQIDataPublish tAirCityHourAQIDataPublish)
	{
		tAirCityHourAQIDataPublish = tAirCityHourAQIDataPublishDao.queryTAirCityHourAQIDataPublishById(tAirCityHourAQIDataPublish);
		return tAirCityHourAQIDataPublish;
	}
	
	
	public TAirCityHourAQIDataPublish avgAQIAirCityHourReport(Map<String, Object> data)
	{
		return this.tAirCityHourAQIDataPublishDao.avgAQIAirCityHourReport(data);
	}

	
	public List<TAirCityHourAQIDataPublish>  groupCountAQIAirCityHourReport(Map<String, Object> data)
	{
		return this.tAirCityHourAQIDataPublishDao.groupCountAQIAirCityHourReport(data);
	}
	
	/**
	 * 多日 同时段
	 * @param data
	 * @return
	 */
	public List<TAirCityHourAQIDataPublish>  queryBySeveralDaysTimeSame(Map<String, Object> data)
	{
		return  tAirCityHourAQIDataPublishDao.queryBySeveralDaysTimeSame(data);
	}
	
	public float calO3_8H_avg(Map<String, Object> data)
	{
		 this.tAirCityHourAQIDataPublishDao.calO3_8H_Avg(data);
		
		return Float.parseFloat(data.get("result").toString());
	}
}
